<?php

    class ProductPriceUtils
    {

        public static function FormatPrice( $price, $currency )
        {
            $formats = self::GetPriceFormats();

            $formatPrice = str_replace( ".00", "", $price );

            foreach ( $formats as $key => $format )
            {
                if ( $key == $currency )
                {
                    $formatPrice = str_replace( "%PRICE%", number_format($formatPrice), $format );
                }
            }

            return $formatPrice;
        }

        private static function GetPriceFormats()
        {
            static $priceFormats;
            if ( !isset( $priceFormats ) )
            {
                $priceFormats = self::LoadPriceFormat();
            }
            return $priceFormats;
        }

        private static function LoadPriceFormat()
        {
            $xml = @file_get_contents( PRICE_FORMAT_FILE );
            $doc = Util::CreateXmlDocument( $xml, true );
            if ( $doc )
            {
                $priceFormats = array();
                $xpath = new XPathHelper( $doc );
                $nodes = $xpath->GetNodes( "/formats/format" );
                foreach ( $nodes as $node )
                {
                    $currency = $node->getAttribute( "currency" );
                    $format = $node->nodeValue;

                    $priceFormats[$currency] = $format;
                }

                return $priceFormats;
            }
            return array();
        }

    }

?>